﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppEnvironment.Lib.StandardMocks
{
    public class LoggerProviderMock : LoggerProvider
    {
        public static event Action<string> OnInfo;
        public static event Action<string> OnError;

        public override void Error(string source, string location, string message)
        {
            string logMessage = string.Format("Error logged: source: {0}, location: {1}, message: {2}", source, location, message);
            Console.WriteLine();
            Console.WriteLine(logMessage);
            Console.WriteLine();
            if (OnError != null)
            {
                OnError(message);
            }
            else
            {
                throw new Exception(logMessage);
            }
        }

        public override void Info(string source, string location, string message)
        {
            string logMessage = string.Format("Info logged: source: {0}, location: {1}, message: {2}", source, location, message);
            Console.WriteLine();
            Console.WriteLine(logMessage);
            Console.WriteLine();
            if (OnInfo != null)
            {
                OnInfo(message);
            }
        }

        protected override void CreateSource(string source)
        {
            //empty
        }

        public static void ClearEvents()
        {
            OnError = null;
            OnInfo = null;
        }
    }
}
